package cn.jiedh.app.meiweidk.Utils.UI;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * @name：RecyclerView分割线
 * @author：司马林
 * @phone：18423134135
 * @createTime：2017/10/21
 */

public class VerticalSpaceItemDecoration extends RecyclerView.ItemDecoration {

    private final int mVerticalSpaceHeight;
    private final boolean mOrientation;

    public VerticalSpaceItemDecoration(int mVerticalSpaceHeight, boolean mOrientation) {
        this.mVerticalSpaceHeight = mVerticalSpaceHeight;
        this.mOrientation = mOrientation;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                               RecyclerView.State state) {
        if (mOrientation) {
            outRect.right = mVerticalSpaceHeight;
        } else {

            if (parent.getChildAdapterPosition(view) == parent.getAdapter().getItemCount() - 1) {
                outRect.top = mVerticalSpaceHeight;
                outRect.bottom = mVerticalSpaceHeight;
            } else if (parent.getChildAdapterPosition(view) != 0) {
                outRect.top = mVerticalSpaceHeight;
            }
        }
    }
}
